﻿#pragma execution_character_set("utf-8")
#include "mainwidget.h"
#include "ui_mainwidget.h"
#include "database.h"
QString MainWidget::currentUser = "";
QString MainWidget::currentphone = "";
QString MainWidget::currentpasswd = "";


MainWidget::MainWidget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::MainWidget)
{
    ui->setupUi(this);
    setFixedSize(1024,600);
    setWindowTitle("珠玉智仓：珠宝店库存管理与可视化分析系统");
    m_LoginWidget       = new LoginWidget(this);   //登录页
    m_ResigerWidget     = new ResigerWidget(this);  //注册页
    m_SelectWidget      = new SelectWidget(this);   //选项页
    m_AdminWidget       = new AdminWidget(this);  //管理员页
    m_ChangeWidget      = new ChangeWidget(this);  //改密码页
    m_ManageWidget      = new ManageWidget(this);  //用户信息管理页
    m_DeliveryWidget    = new DeliveryWidget(this); //售货页
    m_RecordWidget      = new RecordWidget(this);  //记录页
    m_StatisticsWidget  = new StatisticsWidget(this);  //数据查询页
    m_WarehousingWidget = new WarehousingWidget(this);  //入库页
    m_AnalysisWidget    = new AnalysisWidget(this);  //数据分析页
    m_SupplierWidget = new SupplierWidget(this);  //供应商页
    m_OrderWidget = new OrderWidget(this);  //订单页
    m_QualityWidget = new QualityWidget(this);

    ui->stackedWidget->addWidget(m_QualityWidget);

    ui->stackedWidget->addWidget(m_LoginWidget);
    ui->stackedWidget->addWidget(m_ResigerWidget);
    ui->stackedWidget->addWidget(m_SelectWidget);
    ui->stackedWidget->addWidget(m_AdminWidget);
    ui->stackedWidget->addWidget(m_ChangeWidget);
    ui->stackedWidget->addWidget(m_ManageWidget);
    ui->stackedWidget->addWidget(m_DeliveryWidget);
    ui->stackedWidget->addWidget(m_RecordWidget);
    ui->stackedWidget->addWidget(m_StatisticsWidget);
    ui->stackedWidget->addWidget(m_WarehousingWidget);
    ui->stackedWidget->addWidget(m_AnalysisWidget);
    ui->stackedWidget->addWidget(m_SupplierWidget);
    ui->stackedWidget->addWidget(m_OrderWidget);

    ui->stackedWidget->setCurrentWidget(m_LoginWidget);

    connect(m_LoginWidget,SIGNAL(sendDisWidget(QString)),this,SLOT(setWidget(QString)));
    connect(m_ResigerWidget,SIGNAL(sendDisWidget(QString)),this,SLOT(setWidget(QString)));
    connect(m_SelectWidget,SIGNAL(sendDisWidget(QString)),this,SLOT(setWidget(QString)));
    connect(m_AdminWidget,SIGNAL(sendDisWidget(QString)),this,SLOT(setWidget(QString)));
    connect(m_ChangeWidget,SIGNAL(sendDisWidget(QString)),this,SLOT(setWidget(QString)));
    connect(m_ManageWidget,SIGNAL(sendDisWidget(QString)),this,SLOT(setWidget(QString)));
    connect(m_DeliveryWidget,SIGNAL(sendDisWidget(QString)),this,SLOT(setWidget(QString)));
    connect(m_RecordWidget,SIGNAL(sendDisWidget(QString)),this,SLOT(setWidget(QString)));
    connect(m_StatisticsWidget,SIGNAL(sendDisWidget(QString)),this,SLOT(setWidget(QString)));
    connect(m_WarehousingWidget,SIGNAL(sendDisWidget(QString)),this,SLOT(setWidget(QString)));
    connect(m_AnalysisWidget,SIGNAL(sendDisWidget(QString)),this,SLOT(setWidget(QString)));
    connect(m_SupplierWidget,SIGNAL(sendDisWidget(QString)),this,SLOT(setWidget(QString)));
    connect(m_OrderWidget,SIGNAL(sendDisWidget(QString)),this,SLOT(setWidget(QString)));
    connect(m_QualityWidget, SIGNAL(sendDisWidget(QString)),this,SLOT(setWidget(QString)));


    DataBasePri db;
}

MainWidget::~MainWidget()
{
    delete ui;
}

void MainWidget::resizeEvent(QResizeEvent *event)
{
    int m_width = this->width();
    int m_height = this->height();
    ui->stackedWidget->setGeometry(0,0,m_width,m_height);
}

void MainWidget::setWidget(QString str)
{
    if(str == "m_LoginWidget"){
        ui->stackedWidget->setCurrentWidget(m_LoginWidget);
    }
    if(str == "m_ResigerWidget"){
        ui->stackedWidget->setCurrentWidget(m_ResigerWidget);
    }
    if(str == "m_SelectWidget"){
        ui->stackedWidget->setCurrentWidget(m_SelectWidget);
    }
    if(str == "m_AdminWidget"){
        ui->stackedWidget->setCurrentWidget(m_AdminWidget);
    }
    if(str == "m_ManageWidget"){
        ui->stackedWidget->setCurrentWidget(m_ManageWidget);
    }
    if(str == "m_ChangeWidget"){
        ui->stackedWidget->setCurrentWidget(m_ChangeWidget);
    }
    if(str == "m_DeliveryWidget"){
        ui->stackedWidget->setCurrentWidget(m_DeliveryWidget);
    }
    if(str == "m_RecordWidget"){
        ui->stackedWidget->setCurrentWidget(m_RecordWidget);
    }
    if(str == "m_StatisticsWidget"){
        ui->stackedWidget->setCurrentWidget(m_StatisticsWidget);
    }
    if(str == "m_WarehousingWidget"){
        ui->stackedWidget->setCurrentWidget(m_WarehousingWidget);
    }
    if(str == "m_AnalysisWidget"){
        ui->stackedWidget->setCurrentWidget(m_AnalysisWidget);
    }
    if(str == "m_SupplierWidget"){
        ui->stackedWidget->setCurrentWidget(m_SupplierWidget);
    }
    if(str == "m_OrderWidget"){
        ui->stackedWidget->setCurrentWidget(m_OrderWidget);
    }
    if(str == "m_QualityWidget") {
        ui->stackedWidget->setCurrentWidget(m_QualityWidget);  // 确保已在UI中添加此页面
    }
}
